package com.jinlejia.erp.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.freedom.yefeng.yfrecyclerview.YfListAdapter;
import com.freedom.yefeng.yfrecyclerview.YfSimpleViewHolder;
import com.jinlejia.erp.R;
import com.jinlejia.erp.bean.MoreSelectBean;

import java.util.ArrayList;


/**
 * 更多帅选-选中Adapter
 */
public class FilterSelectAdapter extends YfListAdapter<MoreSelectBean> {


    public FilterSelectAdapter(ArrayList<MoreSelectBean> data) {
        super(data);
    }

    @Override
    public RecyclerView.ViewHolder onCreateDataViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_filter_selected_layout, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public RecyclerView.ViewHolder onCreateEmptyViewHolder(ViewGroup parent) {
        View view = new View(parent.getContext());

        return new YfSimpleViewHolder(view);
    }

    @Override
    public void onBindDataViewHolder(RecyclerView.ViewHolder viewHolder, final int i) {

        ((ViewHolder) viewHolder).textView.setText(mData.get(i).getName());

        if( onDataSizeChangeListener != null) {
            onDataSizeChangeListener.onDataSizeChange(mData.size());
        }

        viewHolder.itemView.setTag(mData.get(i));
    }

    @Override
    public RecyclerView.ViewHolder onCreateLoadingViewHolder(ViewGroup parent) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.loading_layout, parent, false);
        return new YfSimpleViewHolder(view);
    }

    @Override
    public RecyclerView.ViewHolder onCreateFooterViewHolder(ViewGroup parent) {
        TextView textView = new TextView(parent.getContext());
        return new YfSimpleViewHolder(textView);
    }

    static final class ViewHolder extends RecyclerView.ViewHolder {

        TextView textView;

        public ViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.tv_select);
        }
    }

    public interface OnDataSizeChangeListener {
        void onDataSizeChange(int size);
    }

    OnDataSizeChangeListener onDataSizeChangeListener;

    public void setOnDataSizeChangeListener(OnDataSizeChangeListener listener) {
        this.onDataSizeChangeListener = listener;
    }

}
